grammar Express;
import BaseLexer,BaseGrammar,Type,TypeDeclaration;

program
    :
    express
    ;

express
    :
          NumberLiteral      # numberValExpr
         | Minus NumberLiteral      # unaryMinusExpr
         | StringLiteral    # stringValExpr
         | (True|False)       # booleanValExpr
         | This               # thisExpr
         | Null               # nullValExpr
         | SimpleName OpenParen  parameters?  CloseParen  # simplifyMethodInvokeExpr
         | SimpleName   # simpleNameExpr
         | New type OpenParen parameters? CloseParen (OpenBrace bodyDeclarations? CloseBrace)?  # newExpr
         | OpenBrace (jsonFieldAssignValue (Comma jsonFieldAssignValue)*)?  CloseBrace # objectValueExpr
         | OpenBracket (express (Comma express)*)?  CloseBracket # arrayValueExpr
         | Final? (Let|Var) SimpleName (Colon type)? (Assign (express))?  # varDeclarationExpr
         | (PlusPlus|MinusMinus)  express  # ppmmPreExpr
         | express (PlusPlus|MinusMinus)  # plusMinusPostExpr
         | express OpenBracket express CloseBracket  # arrayAccessExpr
         | express Dot SimpleName OpenParen  parameters?  CloseParen  # methodInvokeExpr
         | express Dot SimpleName  # fieldAccessExpr
         | express (Multiply| Divide) express  # multiplyDivideExpr
         | express(Plus|Minus)express    # plusMinusExpr
         | express compareOp express     # compareExpr
         | express As type               # typeCastExpr
         | express Assign express        # assignValExpr
         | express (And | Or) express    # andOrExpr
         | OpenParen parameterDeclarations? CloseParen Arrow block   # anonmousFuncExpr
         | OpenParen express CloseParen  # enclosureExpr
         | Not express        # notExpr
         ;

jsonFieldAssignValue
    :
    SimpleName Colon express
    ;

parameters
    :
    parameter (Comma parameter)* Comma?
    ;

parameter
    :
    express
    | Ellipsis express
    ;

compareOp
    :
     Modulo
    | Equal
    | NotEqual
    | GreaterThan
    | GreaterThanEqual
    | LessThan
    | LessThanEqual
    | IdentityEqual
    ;